import { isiOS } from "../utils/index";
import { computed } from "vue";
import { compare } from "../utils/calculation";
import { useGlobalStore } from "../store/global";

/****************** start 请求头/包名 start ******************/
const DANA_PACKAGE_ID_iOS = "BtcDana.IOS-1.3.6-com.indone.online-ios";
const DANA_PACKAGE_ID_Android = "BtcDana-1.8.92-com.indone.online-android";
// const DANA_PACKAGE_ID_Android = "BtcDanaTrading-1.0.5-com.indone.online-android";
// const DANA_PACKAGE_ID_Android = "ForexDana-1.7.7-com.indone.online-android";

export const DANA_PACKAGE_ID = computed(() => {
  try {
    if (!isiOS.value) {
      return DANA_PACKAGE_ID_Android;
    } else {
      return DANA_PACKAGE_ID_iOS;
    }
  } catch (error) {
    console.error("无法按手机获取，测试版本号！将使用 安卓 84 版本");
    return DANA_PACKAGE_ID_Android;
  }
});

/****************** start 兼容包的 PackageID start ******************/
export const BD_PACKAGE_ID = "BtcInvite-1.0.0-com.indone.online-h5";
// export const BD_PACKAGE_ID = "BtcDanaInvest-1.0.1-com.indone.online-android";

// BtcDanaTrading-1.0.5-com.indone.online-android
export const BDT_PACKAGE_ID = "BtcDanaTradingH5-1.0.0-com.indone.online-h5";

export const BDI_PACKAGE_ID = "BtcDanaInvestH5-1.0.0-com.indone.online-h5";

export const BDE_PACKAGE_ID = "BtcDanaEliteH5-1.0.0-com.indone.online-h5";

export const FD_PACKAGE_ID = "ForexdanaInvite-1.0.0-com.indone.online-h5";

export const FDT_PACKAGE_ID = "ForexDanaTradeH5-1.0.0-com.indone.online-h5";

export enum PackageEnum {
  btcDana = DANA_PACKAGE_ID_Android,
  btcInvite = BD_PACKAGE_ID,
  btcDanaTrading = BDT_PACKAGE_ID,
  btcDanaInvest = BDI_PACKAGE_ID,
  btcDanaElite = BDE_PACKAGE_ID,
  forexDana = FD_PACKAGE_ID,
  forexDanaTrade = FDT_PACKAGE_ID,
  btcDanaType = "btcdana",
  btcDanaTradingType = "btcDanaTrading",
  btcDanaInvestType = "btcDanaInvest",
  btcDanaAsiaType = "btcDanaAsia",
  btcDanaEliteType = "btcDanaElite",
  forexDanaType = "forexDana",
  forexDanaTradeType = "forexDanaTrade",
}
/****************** start URL 前缀 start ******************/
export const BASE_URL_PREFIX =
  process.env.NODE_ENV != "development" ? "/fx" : "";

// yarn generate 的时候要加上 /fx 前缀
export const GENERATE_DIR = process.env.WEB_NODE_ENV == "generate" ? "/fx" : "";

/****************** start 调试脚本 start ******************/
export const VCONSOLE_SCRIPT = [
  {
    // src: "//unpkg.com/vconsole@latest/dist/vconsole.min.js",
    src: `https://bdc.btcdana.org/fx/vconsole.min.js`,
    // src: `/fx/vconsole.min.js`,
    type: "text/javascript",
  },
  { innerHTML: "const vConsole = new VConsole()" },
];
// 状态调试
export const VCONSOLE_PLUGIN = [
  // {
  //   // src: "https://cdn.jsdelivr.net/npm/vue-vconsole-devtools@1.0.5/dist/vue_plugin.js",
  //   src: "../vue_plugin.js",
  //   type: "text/javascript",
  // },
  // {
  //   innerHTML:
  //     "const Devtools = window.vueVconsoleDevtools;Devtools.initPlugin(vConsole);",
  // },
];

// 抽美金,正式上链地址
export const BDC_blockchain_Host = "https://optimistic.etherscan.io/tx/";

// BDC 上链枚举
export enum BdcBlockchainHost {
  optimistic = "https://optimistic.etherscan.io/tx/",
  sepoliaOptimism = "https://sepolia-optimism.etherscan.io/tx/",
}

// 图片格式 formats
export const IMAGE_FORMATS = ["webp", "png", "jpg"]; // , "jpeg","avif",

/****************** start app 下载地主 start ******************/
// BtcDana 安卓下载地址
export const BTC_DANA_ANDROID_DOWN_URL =
  "https://btcdana.onelink.me/ZQVj/anhags2k" as string;

// BtcDana asia 安卓下载地址
export const BTC_DANA_ANDROID_ASIA_DOWN_URL =
  "https://play.google.com/store/apps/details?id=com.dana.asia" as string;

// BtcDana ios下载地址
export const BTC_DANA_IOS_DOWN_URL =
  "https://btcdana.onelink.me/Im9V/kpndzej3?af_force_deeplink=true" as string;

// BtcDana apk下载地址
export const BTC_DANA_APK_DOWN_URL =
  "https://reg.btcdana.org/apk/BtcDana.apk" as string;

/****************** start 跳转 app 路由列表 start ******************/
// 上线BDC 版本;需要兼容以前的桥接
const android = {
  BtcDana: "BtcDana-1.8.89-com.indone.online-android",
  BtcDanaAsia: "BtcDanaAsia-1.0.17-com.indone.online-android",
  BtcDanaElite: "BtcDanaElite-1.0.0-com.indone.online-android", // 3 月 27 号新加的包
  BtcDanaTrading: "BtcDanaTrading-1.0.4-com.indone.online-android", // 4 月 24 号新加的包
  ForexDanaTrade: "ForexDanaTrade-1.0.12-com.indone.online-android", // 6 月 07 号新加的包
  ForexDana: "ForexDana-1.7.7-com.indone.online-android", // 24.11.07 号新加的包
};

/***************** start iOS 1.3.7 桥接优化需求 start *****************/
// iOS 版本是不是大于等于 1.3.7;
let isiOSVer_gte137: any = null;

// 判断是不是 iOS 1.3.7 版本以上
const is137_iOS = () => {
  if (isiOSVer_gte137 != null) return isiOSVer_gte137;
  if (isiOS.value) {
    const globalStore = useGlobalStore();
    let compareVersion: any = compare(
      globalStore.$state.packageId,
      "BtcDana.IOS-1.3.7-com.indone.online-ios"
    );
    if (compareVersion >= 0) {
      isiOSVer_gte137 = true;
      return true;
    } else {
      isiOSVer_gte137 = false;
      return false;
    }
  } else {
    isiOSVer_gte137 = true;
    return true;
  }
};

/***************** end iOS 1.3.7 桥接优化需求 end *****************/

export const JUMPAPPS = (val?: any) => {
  return {
    // 积分商城
    integralShop: !is137_iOS()
      ? "native://page/integralShop"
      : "https://btcdana.com/PointsMall",
    // 任务中心
    taskCenter: !is137_iOS()
      ? "native://page/taskCenter?type=1"
      : "https://btcdana.com/TaskCenter?index=1",

    // 行情
    market: !is137_iOS()
      ? "native://page/market"
      : "https://btcdana.com/PriceFragment",

    // 跳转绑定,手机和邮箱
    bindAccountList: !is137_iOS()
      ? "native://page/bindAccountList"
      : "https://btcdana.com/Other?activity=BindingVerificationActivity",

    // 实名
    realName: !is137_iOS()
      ? "native://page/realName"
      : "https://btcdana.com/CertificationActivity",

    // 原生充值页面 这个有问题: 安卓跳转到了 BTC 的行情页面了
    recharge: !is137_iOS()
      ? "native://page/recharge"
      : "https://btcdana.com/RechargeActivity",

    // 模拟
    demoMarket: !is137_iOS()
      ? "native://page/demoMarket"
      : "https://btcdana.com/SimulateTradingActivity",

    // 圈子-tab-BDC
    circle2: !is137_iOS()
      ? "native://page/circle?index=2"
      : "https://btcdana.com/CommunityBDC",
    // 联系客服
    openChat: !is137_iOS()
      ? "native://page/openChat"
      : "https://btcdana.com/ZopimChatHelper",
    // 私聊列表
    ChatroomList: !is137_iOS()
      ? "native://page/messageCenter?index=0"
      : "https://btcdana.com/ChatroomList",

    // 跳转直播间
    liveRoom: !is137_iOS()
      ? `native://page/liveStream?activityId=1004&liveId=${
          (val || {}).liveId || ""
        }`
      : `https://btcdana.com/LiveActivity?activityId=1004&liveId=${
          (val || {}).liveId || ""
        }&liveState=1`,
    // tabbar 我的
    mine: !is137_iOS()
      ? "native://page/wallets"
      : "https://btcdana.com/MineFragment",

    // 激活避险账户-激活
    hedgeAccount: () => {
      return {
        routeKey: !is137_iOS()
          ? "native://page/assets?showGuide=1"
          : "https://btcdana.com/hedgingWallet", // '"onAsset",
        compatibleVersionList: Object.values({
          ...android,
          ...{
            ForexDanaTrade: "ForexDanaTrade-1.0.25-com.indone.online-android", // 1.0.25 支持
          },
        }),
        jumpUrl: !is137_iOS()
          ? "native://page/wallets"
          : "https://btcdana.com/MineFragment", // 通用跳转
      };
    },
    // 激活避险账户-充值
    hedgingWallet: () => {
      return {
        routeKey: !is137_iOS()
          ? "native://page/hedgeAccount"
          : "https://btcdana.com/hedgingWallet", // hedgingWallet
        compatibleVersionList: Object.values({
          ...android,
          ...{
            ForexDanaTrade: "ForexDanaTrade-1.0.25-com.indone.online-android", // 1.0.25 支持
          },
        }),
        jumpUrl: !is137_iOS()
          ? "native://page/wallets"
          : "https://btcdana.com/MineFragment", // 通用跳转
      };
    },
    // 邀请好友页面
    inviteFriends: () => {
      return {
        routeKey: !is137_iOS()
          ? "native://page/inviteFriend"
          : "https://btcdana.com/invite", // onInvite
        compatibleVersionList: Object.values({
          ...android,
          ...{
            ForexDanaTrade: "ForexDanaTrade-1.0.25-com.indone.online-android", // 1.0.25 支持
          },
        }),
        jumpUrl: !is137_iOS()
          ? "native://page/wallets"
          : "https://btcdana.com/MineFragment", // 通用跳转
      };
    },

    // 获取 App 剪贴板内容
    getAppCopy: () => {
      return Object.values({
        ...android,
        ...{
          BtcDana: "BtcDana-1.8.90-com.indone.online-android",
          BtcDanaAsia: "BtcDanaAsia-1.0.18-com.indone.online-android",
          BtcDanaTrading: "BtcDanaTrading-1.0.8-com.indone.online-android",
          ForexDanaTrade: "ForexDanaTrade-1.0.25-com.indone.online-android",
        },
      });
    },
    // 老版本不展示,邀友的某些任务
    lotteryV2YyTaskFilter: () => {
      return {
        BtcDana: "BtcDana-1.8.94-com.indone.online-android",
        "BtcDana.IOS": "BtcDana.IOS-1.3.3-com.indone.online-ios",
        BtcDanaTrading: "BtcDanaTrading-1.0.8-com.indone.online-android",
        BtcDanaAsia: "BtcDanaAsia-1.0.17-com.indone.online-android",
        BtcDanaElite: "BtcDanaElite-1.0.0-com.indone.online-android", // 3 月 27 号新加的包
        ForexDanaTrade: "ForexDanaTrade-1.0.12-com.indone.online-android", // 6 月 07 号新加的包
        ForexDana: "ForexDana-1.7.7-com.indone.online-android", // 24.11.07 号新加的包
      };
    },
    // 支付渠道: 安卓: 是不是老包,老包 120 渠道不支持,新包都支持;  iOS(只有一个包): 都可以
    channelPay120: {
      BtcDana: "BtcDana-1.8.91-com.indone.online-android",
      BtcDanaAsia: "BtcDanaAsia-1.0.19-com.indone.online-android",
    },
    // 使用默认浏览器打开链接
    defaultBrowserOpen: () => {
      return {
        ...android,
        ...{
          BtcDana: "BtcDana-1.8.91-com.indone.online-android",
          BtcDanaAsia: "BtcDanaAsia-1.0.19-com.indone.online-android",
          ForexDanaTrade: "ForexDanaTrade-1.0.25-com.indone.online-android",
          ForexDana: "ForexDana-1.7.8-com.indone.online-android",
        },
      };
    },
    // 导航桥接兼容
    navBar: () => {
      return Object.values({
        ...android,
        ...{
          BtcDana: "BtcDana-1.8.83-com.indone.online-android",
          BtcDanaAsia: "BtcDanaAsia-1.0.8-com.indone.online-android",
        },
      });
    },
    // 全局跳转拦截
    globalRoute: () => {
      return Object.values({
        ...android,
        ...{
          "BtcDana.IOS": "BtcDana.IOS-1.3.0-com.indone.online-ios",
          BtcDana: "BtcDana-1.8.86-com.indone.online-android",
          BtcDanaAsia: "BtcDanaAsia-1.0.8-com.indone.online-android",
        },
      });
    },
  };
};
